/// 错题计数
import {ref, Ref, watchEffect} from "vue";
import {Tag} from "../Tag";
import {useDialog} from 'naive-ui'
import {ITopic} from "../Topic";

/// 错题次数 ,它实际上还充当 你认为此题目的 难易程度,所以它可以负数
/// 我很喜欢这个标签
export class TagWrongCount implements Tag<"TagWrongCount",Ref<number>>{
	tag_name:"TagWrongCount" = "TagWrongCount";
	
	
	
	tag_color(self: Ref<number>): "default" | "primary" | "info" | "success" | "warning" | "error" | { color?: string; borderColor?: string; textColor?: string } {
		return "warning";
	}
	
	view(self: Ref<number>,topic:ITopic<any>): string {
		return `错[${self.value}]`;
	}
	
	on_click(event:any,self: Ref<number>, ...any: any[]): undefined {
		return undefined;
	}
	
	on_click2(event:any,self: Ref<number>, ...any: any[]): undefined {
		return undefined;
	}
	
	on_wheel(event:any,self: Ref<number>,...any: any[]): any {
		if (event.wheelDelta > 0 || event.detail < 0) {     //当鼠标滚轮向上滚动时
			self.value++;
		} else if (event.wheelDelta < 0 || event.detail > 0) {     //当鼠标滚轮向下滚动时
			self.value--;
		}
	}
	
	data_as_storage(self: Ref<number>): any {
		return self.value;
	}
	
	storage_as_data(storage: any,self ?: Ref<number>): Ref<number> {
		if(self == undefined){
			return ref(storage);
		}
		self.value = storage;
		return self;
	}
	
}


/**
 * @switch_editor 初始必须是 false , 不然玩个球
 */
export type TagNoteData = {text:Ref<string>,switch_editor:Ref<boolean>};
/// 笔记 todo
/// todo 感觉没啥必要,毕竟可以直接修改 解析,这样显得它非常无用
/// todo 除非给它一个 展示样式,比如 MarkDown
export class TagNote implements Tag<"TagNote",TagNoteData>{
	tag_name:"TagNote" = "TagNote";
	tag_color(self:TagNoteData): "default" | "primary" | "info" | "success" | "warning" | "error" | { color?: string; borderColor?: string; textColor?: string } {
		return "success";
	}
	
	view(self: TagNoteData): string {
		return `笔记[${self.text.value.length}]`;
	}
	
	on_click(event:any,self: TagNoteData, t:any, ...any: any[]): any {
		self.switch_editor.value = true;
	}
	
	on_click2(event:any,self:TagNoteData, ...any: any[]): undefined {
		return undefined;
	}
	
	on_wheel(event:any,self:TagNoteData, ...any: any[]): undefined {
		return undefined;
	}
	
	data_as_storage(self: TagNoteData): any {
		return {
			text:self.text.value,
			switch_editor:self.switch_editor.value
		}
	}
	
	storage_as_data(storage: any,self ?: TagNoteData): TagNoteData {
		if(self == undefined){
			return {
				text:ref(storage.text),
				switch_editor:ref(storage.switch_editor)
			};
		}
		self.text.value = storage.text;
		self.switch_editor.value = storage.switch_editor;
		return self;
	}
	
}
